package com.vtb.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.vtb.base.VtbException;
import com.vtb.entity.MessageCount;
import com.vtb.inter.VtbDaoInterface;
import com.vtb.utils.JdbcUtils;
/**
 * OtDao 实现类
 *
 * @author Chen Tao
 * @date 2012-7-1 下午05:04:57
 */
@SuppressWarnings("deprecation")
public class OtDaoImpl implements VtbDaoInterface<MessageCount, MessageCount> {
	private static final Log log = LogFactory.getLog(OtDaoImpl.class);
    @Override
    public MessageCount get(MessageCount messageCount) {
        try {
            QueryRunner qr = new QueryRunner();
            String sql = "select * from otdata where uni=?";
            messageCount = (MessageCount) qr.query(JdbcUtils.getConnection(), sql,messageCount.getUni(),new BeanHandler(MessageCount.class));
            return messageCount;
        } catch (SQLException e) {
            log.error("查找otdata错误：", e);
            throw new VtbException("查找otdata错误"+e);
        }
    }
    @Override
    public void insert(MessageCount messageCount) {
        try {
            QueryRunner qr = new QueryRunner();
            String sql = "insert into otdata(uni,para) values (?,?)";
            Object[] params = {messageCount.getUni(),messageCount.getPara()};
            qr.update(JdbcUtils.getConnection(), sql, params);
        } catch (SQLException e) {
            log.error("插入otdata错误：", e);
            throw new VtbException("插入otdata错误",e);
        }
        
    }
    @Override
    public void update(MessageCount messageCount) {
        try {
            QueryRunner qr = new QueryRunner();
            String sql = "update otdata set para=? where uni=?";
            Object[] params = {messageCount.getPara(),messageCount.getUni()};
            qr.update(JdbcUtils.getConnection(), sql, params);
        } catch (SQLException e) {
            log.error("更新otdata错误：", e);
            throw new VtbException("更新otdata错误"+e);
        }
    }

    @Override
    public void del(MessageCount t) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public List<MessageCount> getAll() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public List<MessageCount> getAllInfo() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void insertAll(MessageCount k) {
        // TODO Auto-generated method stub
        
    }
}
